package com.project.service.impl;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.project.bean.LssueBean;
import com.project.bean.OutLssueBean;
import com.project.dao.LssueDao;
import com.project.service.LssueService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.time.LocalDate;

/**
 * 出库
 */
@Service
@Transactional
@SuppressWarnings("all")
public class LssueServiceImpl extends ServiceImpl<LssueDao, LssueBean> implements LssueService {
    @Override
    public IPage<LssueBean> findAllLssue(int pageNO, int pageSize) {
        Page<LssueBean> page = new Page<>(pageNO, pageSize);
        IPage<LssueBean> iPage = this.page(page);
        return iPage;
    }

    @Override
    public void addLssue(LssueBean lssueBean) {
        this.baseMapper.insert(lssueBean);
    }

    @Override
    public void updateOutLssue(int id, int num) {
        this.baseMapper.updateOutLssue(id, num);
    }

    @Override
    public OutLssueBean findId(int lssueId) {
        return this.baseMapper.findId(lssueId);
    }

    @Override
    public IPage<LssueBean> findName(int pageNO, int pageSize, String lssueClass, LocalDate startTime, LocalDate endTime) {
        Page<LssueBean> page = new Page<>(pageNO, pageSize);
        QueryWrapper<LssueBean> wrapper = new QueryWrapper<>();
        if (lssueClass != "" && !lssueClass.equals("")) {
            wrapper.like("lssuec_class", lssueClass);
        }
        if (startTime != null) {
            wrapper.ge("lssue_day", startTime);
        }
        if (endTime != null) {
            wrapper.le("lssue_day", endTime);
        }
        IPage<LssueBean> iPage = this.page(page, wrapper);
        return iPage;
    }

    @Override
    public void delLssue(int lssueId) {
        this.baseMapper.delLssue(lssueId);
    }
}
